Component({
  properties: {
    id: Number
  },
  data: {
    lineUpOne: {},
    likeColor: 'inherit',
    x: 0,
    y: 400
  },
  methods: {
    lineupDetailData() {

      wx.request({
        url:'https://wxapi.db101.cn/v1/jcc/lineup/one',
        method: 'POST',
        data: {
          // @ts-ignore
          "id": this.data.id
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: (res) => {
          // @ts-ignore
          this.setData( {lineUpOne: res.data.data})
        }
      });

      // 查询是否已经被收藏
      wx.request({
        url:'https://wxapi.db101.cn/v1/jcc/favorites/one',
        method: 'POST',
        data: {
          // @ts-ignore
          "userId": wx.getStorageSync('user').id,
          // @ts-ignore
          "lineupId": this.data.id
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: (res) => {
          // @ts-ignore
          if (res.data.code == 200 && res.data.data) {
            // @ts-ignore
            this.setData( {likeColor: 'red'})
          }
        }
      })
    },
    lineupFav() {
      wx.request({
        url:'https://wxapi.db101.cn/v1/jcc/favorites/add',
        method: 'POST',
        data: {
          // @ts-ignore
          "userId": wx.getStorageSync('user').id,
          // @ts-ignore
          "lineupId": this.data.lineUpOne.id
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: (res) => {
          // @ts-ignore
          if (res.data.code == 200) {
            wx.showToast({ title: '收藏成功', icon: 'none' });
            // @ts-ignore
            this.setData( {likeColor: 'red'})
          }
        }
      })
    },
    setX() {
      let that = this;
      wx.getSystemInfo({
        success: function(res) {
          // @ts-ignore
          that.setData( {x: res.windowWidth})
        },
        fail: function(err) {
          console.error("获取屏幕信息失败", err)
        }
      });
    }
  },
  lifetimes: {
    attached: function() {
      // @ts-ignore
      this.lineupDetailData();
      // @ts-ignore
      this.setX();
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  }
})
